package com.hwl.demo23.entity;

import com.hwl.demo23.service.Action;
import com.hwl.demo23.service.Person;

import java.util.ArrayList;
import java.util.List;

/**
 * 对象结构
 *
 * @author sentry
 * @since 2023-03-26
 */
public class ObjectStructure {

    private final List<Person> elements = new ArrayList<>();

    public void attach(Person element) {
        elements.add(element);
    }

    public void detach(Person element) {
        elements.remove(element);
    }

    public void display(Action visitor) {
        for (Person e : elements) {
            e.accept(visitor);
        }
    }
}
